package practise.alogrithm.hundredInterviewQuestions.secondTime;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Richard on 7/27/2014.
 */
public class MinInARotationArray {

    public Integer get(List<Integer> array){
        int start=0, end=array.size()-1;
        for(int middle=(start+end)/2;end-1>start;middle=(start+end)/2){
            if(array.get(middle)>array.get(end)){
                start = middle;
            }
            else {
                end =middle;
            }
        }
        return Math.min(array.get(start),array.get(end));
    }

    public static void main(String[] args){
        System.out.print("Result:"+new MinInARotationArray().get(new ArrayList<Integer>(Arrays.asList(new Integer[]{4,5,6,7,1,2,3}))));
    }
}
